{include file='public/header' /}
</head>
<body style="padding: 10px;">
<form class="layui-form">
    <input type="hidden" name="gid" value="{$role.gid}">
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" value="{$role.title}">
        </div>
    </div>

    <div class="layui-form-itme">
        <label class="layui-form-label">权限菜单</label>
        <!--<button class="layui-btn layui-btn-xs" onclick="quxuan();return false;" id="owner_all">迷你按钮</button>-->
        {volist name="menus" id="vo"}
        <hr>
        <div class="layui-input-block">
            <input type="checkbox" name="menu[{$vo.mid}]" lay-skin="primary" title="{$vo.title}" {:isset($role['rights']) && $role['rights'] && in_array($vo.mid,$role['rights'])?'checked':''}>
            <hr>
            {volist name="vo.children" id="cvo"}
            <input type="checkbox" name="menu[{$cvo.mid}]" lay-skin="primary" title="{$cvo.title}" {:isset($role['rights']) && $role['rights'] && in_array($cvo.mid,$role['rights'])?'checked':''}>
            {/volist}
        </div>
        {/volist}
    </div>
</form>

<div class="layui-form-item" style="margin-top:10px;">
    <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form'],function(){
        var form = layui.form;
        layer = layui.layer;
        $ = layui.jquery;
    });
    
    function quxuan() {
        var ch = document.getElementsByClassName("layui-unselect");
        ch.checked = true;
        ch.className ="layui-unselect layui-form-checkbox layui-form-checked";

        // alert($(".layui-unselect").html());
        // $('.layui-unselect').checked = true ;
        // $(".layui-unselect").addClass("layui-form-checked");
    }

    function save(){
        var title = $.trim($('input[name="title"]').val());
        if(title==''){
            layer.msg('请填写角色名称',{'icon':2});
            return;
        }
        $.post('__PUBLIC__/admin/roles/save',$('form').serialize(),function(res){
            if(res.code>0){
                layer.msg(res.msg,{'icon':2});
            }else{
                layer.msg(res.msg,{'icon':1});
                setTimeout(function(){parent.window.location.reload();},1000);
            }
        },'json');
    }
</script>